package tree;
/*初始化树默认有一个节点，其id和element均为null*/
public class BinarySortTree<T1,T2> {
    BinarySortTreeNode<T1,T2> root;

    public BinarySortTree() {
        root = new BinarySortTreeNode<>();
    }

    /*添加具有相同id的会替换对应节点*/
    public void add(T1 id,T2 element){
        if (root.getId()==null){
            root.setId(id);
            root.setElement(element);
        }else {
            BinarySortTreeNode<T1,T2> node = new BinarySortTreeNode<T1,T2>(id,element);
            root.add(node);
        }
    }
    public void preOrderPrint(){
        if(root.getId()==null){
            return;
        }
        root.preOrderPrint();
    }

    public T2 search(T1 id){
        if(root.getId()==null){
            return null;
        }
        return root.search(id);
    }

    public void delete(T1 id){
        if(root.getId()==null){
            return;
        }
        root.delete(id,null);
    }
}
